//
//  wmCgpIJLCFListBmapCellkeSwUo.m
//  Jlcf_ios
//
//  Created by Ji on 2018/9/27.
//  Copyright © 2018 ski. All rights reserved.
//

#import "wmCgpIJLCFListBmapCellkeSwUo.h"
#import "ZXYCircleProgress.h"
#import "zzknojJLCFListDetailViewControllerFwedjf.h"
#import "rmMqyfJLCFLoginAndRegisterControllerFbzYtj.h"

@interface wmCgpIJLCFListBmapCellkeSwUo ()

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIImageView *vGAUzptypeImgBvuKut;

@property (nonatomic, strong) UIImageView *clQHSlriseImgiiCpNh;

@property (nonatomic, strong) UILabel *DqlqILaprLabelIPueGU;
@property (nonatomic, strong) UILabel *tdWNHoaprTitleLabelzSRvts;

@property (nonatomic, strong) UILabel *BPFLwEdayLabelHMABqA;
@property (nonatomic, strong) UILabel *mzesIYdayTitleLabeliruIgN;

@property (nonatomic, strong) UILabel *zEvlulleftMoneyLabelFuqTph;
@property (nonatomic, strong) UILabel *remTvtacpmoneyLabelIfJqAd;

@property (nonatomic, strong) ZXYCircleProgress *pxXNCScircleProgressvvRDpO;

@property (nonatomic, strong) UIView *MhOsdeprogressViewSXAiXa;
@property (nonatomic, strong) CAShapeLayer *ZLmcEJshapeLayerWDClkp;

@property (nonatomic, strong) UIImageView *WfMpnlnoticeViewcVGfah;
@property (nonatomic, strong) UILabel *uBShqXnoticeLabelBqMXlb;

@end

@implementation wmCgpIJLCFListBmapCellkeSwUo

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)reloadData {
    
    if (self.aeeeWcbmapModelgTZMIY) {
        if (!self.titleLabel) {
            self.titleLabel = [UILabel new];
            self.titleLabel.font = FONT(12);
            [self addSubview:self.titleLabel];
        }
        
        if (self.titleLabel) {
            self.titleLabel.text = self.aeeeWcbmapModelgTZMIY.name;
            [self.titleLabel sizeToFit];
            self.titleLabel.top = 9;
            self.titleLabel.left = 15;
            self.titleLabel.textColor = ![self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"] ? QTZ_Gray153 : QTZ_Gray51;
            if ([self.aeeeWcbmapModelgTZMIY.scales integerValue] == 1) {//还款中
            }
        }
        
        if (!self.vGAUzptypeImgBvuKut) {
            self.vGAUzptypeImgBvuKut = [UIImageView new];
            [self addSubview:self.vGAUzptypeImgBvuKut];
        }
        
        if (self.vGAUzptypeImgBvuKut) {
            self.vGAUzptypeImgBvuKut.image = [UIImage imageNamed:[self.aeeeWcbmapModelgTZMIY.use isEqualToString:@"0"] ? @"icon_list_new" : ![self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"] ? @"icon_list_listBmap_gray" :  @"icon_list_listBmap"];
            [self.vGAUzptypeImgBvuKut sizeToFit];
            self.vGAUzptypeImgBvuKut.centerY = self.titleLabel.centerY;
            self.vGAUzptypeImgBvuKut.left = self.titleLabel.right + 10;
        }
        
        if (!self.clQHSlriseImgiiCpNh) {
            self.clQHSlriseImgiiCpNh = [[UIImageView alloc] init];
            [self addSubview:self.clQHSlriseImgiiCpNh];
        }
        
        if (self.clQHSlriseImgiiCpNh) {
            self.clQHSlriseImgiiCpNh.image =  [UIImage imageNamed:![self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"] ? @"icon_list_rise_gray" : @"icon_list_rise"];
            [self.clQHSlriseImgiiCpNh sizeToFit];
            self.clQHSlriseImgiiCpNh.right = FULL_WIDTH;
            self.clQHSlriseImgiiCpNh.hidden = [self.aeeeWcbmapModelgTZMIY.addApr isEqualToString:@"0"];
        }
        
        if (!self.DqlqILaprLabelIPueGU) {
            self.DqlqILaprLabelIPueGU = [UILabel new];
            self.DqlqILaprLabelIPueGU.font = FONT(24);
            [self addSubview:self.DqlqILaprLabelIPueGU];
            
            [self bk_whenTapped:^{
                if ([self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"]) {
                    if ([JLCFRegisterService shareService].hasToken){
                        zzknojJLCFListDetailViewControllerFwedjf *detailVC = [zzknojJLCFListDetailViewControllerFwedjf new];
                        detailVC.bxiKZJproTitlehvcALF = self.aeeeWcbmapModelgTZMIY.name;
                        detailVC.proId = self.aeeeWcbmapModelgTZMIY.id;
                        [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:detailVC animated:YES];
                    }else{
                        rmMqyfJLCFLoginAndRegisterControllerFbzYtj *vc = [rmMqyfJLCFLoginAndRegisterControllerFbzYtj new];
                        
                        if (![[JinLiCaiFuApplicationEntrace shareEntrance] isContainVC:@"LoginAndRegisterController"]) {
                            [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:vc animated:YES];
                            [vc showNotice:@"请登陆或注册"];
                        }
                    }
                }
            }];
        }
        
        if (self.DqlqILaprLabelIPueGU) {
            self.DqlqILaprLabelIPueGU.textColor = ![self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"] ? QTZ_Gray153 :  Theme_Color;
            if ([self.aeeeWcbmapModelgTZMIY.addApr isEqualToString:@"0"]) {
                self.DqlqILaprLabelIPueGU.text = [NSString stringWithFormat:@"%@%%", self.aeeeWcbmapModelgTZMIY.realApr];
            } else {
                NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%%+%@%%", self.aeeeWcbmapModelgTZMIY.realApr, self.aeeeWcbmapModelgTZMIY.addApr]];
                [attributeStr addAttribute:NSFontAttributeName value:FONT(15) range:NSMakeRange(0, attributeStr.length)];
                [attributeStr addAttribute:NSFontAttributeName value:FONT(24) range:NSMakeRange(0, self.aeeeWcbmapModelgTZMIY.realApr.length)];
                self.DqlqILaprLabelIPueGU.attributedText = attributeStr;
            }
            [self.DqlqILaprLabelIPueGU sizeToFit];
            self.DqlqILaprLabelIPueGU.left = self.titleLabel.left;
            self.DqlqILaprLabelIPueGU.top = 40;
        }
        
        if (!self.tdWNHoaprTitleLabelzSRvts) {
            self.tdWNHoaprTitleLabelzSRvts = [UILabel labelWithText:@"期望年化利率" textColor:QTZ_Gray153 font:FONT(10)];
            self.tdWNHoaprTitleLabelzSRvts.left = self.DqlqILaprLabelIPueGU.left;
            self.tdWNHoaprTitleLabelzSRvts.top = self.DqlqILaprLabelIPueGU.bottom + 10;
            [self addSubview:self.tdWNHoaprTitleLabelzSRvts];
        }
        
        if (!self.BPFLwEdayLabelHMABqA) {
            self.BPFLwEdayLabelHMABqA = [UILabel new];
            [self addSubview:self.BPFLwEdayLabelHMABqA];
        }
        
        if (self.BPFLwEdayLabelHMABqA) {
            self.BPFLwEdayLabelHMABqA.textColor = ![self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"] ? QTZ_Gray153 :  QTZ_Gray66;
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@天", self.aeeeWcbmapModelgTZMIY.timeLimitDay]];
            [attributeStr addAttribute:NSFontAttributeName value:FONT(12) range:NSMakeRange(0, attributeStr.length)];
            [attributeStr addAttribute:NSFontAttributeName value:FONT(19) range:NSMakeRange(0, self.aeeeWcbmapModelgTZMIY.timeLimitDay.length)];
            self.BPFLwEdayLabelHMABqA.attributedText = attributeStr;
            [self.BPFLwEdayLabelHMABqA sizeToFit];
            self.BPFLwEdayLabelHMABqA.centerX = FULL_WIDTH / 2;
            self.BPFLwEdayLabelHMABqA.bottom = self.DqlqILaprLabelIPueGU.bottom;
        }
        
        if (!self.mzesIYdayTitleLabeliruIgN) {
            self.mzesIYdayTitleLabeliruIgN = [UILabel labelWithText:@"投资期限" textColor:QTZ_Gray153 font:FONT(10)];
            self.mzesIYdayTitleLabeliruIgN.centerX = self.BPFLwEdayLabelHMABqA.centerX;
            self.mzesIYdayTitleLabeliruIgN.bottom = self.tdWNHoaprTitleLabelzSRvts.bottom;
            [self addSubview:self.mzesIYdayTitleLabeliruIgN];
        }
        
//        if (!self.pxXNCScircleProgressvvRDpO) {
//            self.pxXNCScircleProgressvvRDpO = [[ZXYCircleProgress alloc] initWithFrame:CGRectMake(0, 0, 30, 30) progress:0];
//            self.pxXNCScircleProgressvvRDpO.right = FULL_WIDTH - 38;
//            self.pxXNCScircleProgressvvRDpO.top = 42;
//            self.pxXNCScircleProgressvvRDpO.progressWidth = 2;
//            self.pxXNCScircleProgressvvRDpO.bottomWitdh = 1;
//            self.pxXNCScircleProgressvvRDpO.bottomColor = [UIColor colorWithRed:252 / 255.0f green:97 / 255.0f blue:78 / 255.0f alpha:.4];
//            self.pxXNCScircleProgressvvRDpO.topColor = Theme_Color;
//            [self addSubview:self.pxXNCScircleProgressvvRDpO];
//        }
//
//        if (self.pxXNCScircleProgressvvRDpO) {
//            if (![self.aeeeWcbmapModelgTZMIY.status isEqualToString:@"1"]) {
//                self.pxXNCScircleProgressvvRDpO.progress = 1;
//                self.pxXNCScircleProgressvvRDpO.progressText = @"购买";
//                self.pxXNCScircleProgressvvRDpO.topColor = QTZ_Gray153;
//            } else {
//                self.pxXNCScircleProgressvvRDpO.progress = [self.aeeeWcbmapModelgTZMIY.scales floatValue];
//            }
//        }
        
        if (!self.zEvlulleftMoneyLabelFuqTph) {
            self.zEvlulleftMoneyLabelFuqTph = [UILabel new];
            [self addSubview:self.zEvlulleftMoneyLabelFuqTph];
        }
        
        if (self.zEvlulleftMoneyLabelFuqTph) {
            self.zEvlulleftMoneyLabelFuqTph.textColor = QTZ_Gray66;
            self.zEvlulleftMoneyLabelFuqTph.textAlignment = NSTextAlignmentRight;
            
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@元", self.aeeeWcbmapModelgTZMIY.remmoney]];
            [attributeStr addAttribute:NSFontAttributeName value:FONT(12) range:NSMakeRange(0, attributeStr.length)];
            [attributeStr addAttribute:NSFontAttributeName value:FONT(19) range:NSMakeRange(0, self.aeeeWcbmapModelgTZMIY.remmoney.length)];
            self.zEvlulleftMoneyLabelFuqTph.attributedText = attributeStr;
            [self.zEvlulleftMoneyLabelFuqTph sizeToFit];
            self.zEvlulleftMoneyLabelFuqTph.right = FULL_WIDTH - 20;
            self.zEvlulleftMoneyLabelFuqTph.bottom = self.DqlqILaprLabelIPueGU.bottom;
        }
        
        if (!self.remTvtacpmoneyLabelIfJqAd) {
            self.remTvtacpmoneyLabelIfJqAd = [UILabel new];
            self.remTvtacpmoneyLabelIfJqAd.textColor = QTZ_Gray153;
            self.remTvtacpmoneyLabelIfJqAd.font = FONT(8);
            self.remTvtacpmoneyLabelIfJqAd.text = @"剩余可投金额";
            [self.remTvtacpmoneyLabelIfJqAd sizeToFit];
            self.remTvtacpmoneyLabelIfJqAd.right = FULL_WIDTH - 40;
            self.remTvtacpmoneyLabelIfJqAd.bottom = self.tdWNHoaprTitleLabelzSRvts.bottom;
            [self addSubview:self.remTvtacpmoneyLabelIfJqAd];
        }
        
        if (!self.MhOsdeprogressViewSXAiXa) {
            self.MhOsdeprogressViewSXAiXa = [[UIView alloc] init];
            self.MhOsdeprogressViewSXAiXa.frame = CGRectMake(0, 0, SCREEN_WIDTH, 2);
            self.MhOsdeprogressViewSXAiXa.centerY = 135;
            
            [self addSubview:self.MhOsdeprogressViewSXAiXa];
            
            UIBezierPath * bezierPath = [UIBezierPath bezierPath];
            [bezierPath moveToPoint:CGPointMake(0, 1)];
            [bezierPath addLineToPoint:CGPointMake(SCREEN_WIDTH, 1)];
            
            CAShapeLayer *bgLayer = [CAShapeLayer layer];
            bgLayer.fillColor = [UIColor clearColor].CGColor;
            bgLayer.lineWidth = 2.f;
            bgLayer.strokeColor = QTZ_Gray230.CGColor;
            bgLayer.strokeStart = 0;
            bgLayer.strokeEnd = 1;
            bgLayer.lineCap = kCALineCapRound;
            bgLayer.path = bezierPath.CGPath;
            [self.MhOsdeprogressViewSXAiXa.layer addSublayer:bgLayer];
            
            _ZLmcEJshapeLayerWDClkp = [CAShapeLayer layer];
            _ZLmcEJshapeLayerWDClkp.fillColor = [UIColor clearColor].CGColor;
            _ZLmcEJshapeLayerWDClkp.lineWidth = 2.f;
            _ZLmcEJshapeLayerWDClkp.lineCap = kCALineCapRound;
            _ZLmcEJshapeLayerWDClkp.strokeColor = RGB(207, 147, 111).CGColor;
            _ZLmcEJshapeLayerWDClkp.strokeStart = 0;
            _ZLmcEJshapeLayerWDClkp.strokeEnd = 0;
            _ZLmcEJshapeLayerWDClkp.path = bezierPath.CGPath;
            [self.MhOsdeprogressViewSXAiXa.layer addSublayer:_ZLmcEJshapeLayerWDClkp];
        }
        
        double scales = [self.aeeeWcbmapModelgTZMIY.scales doubleValue];
        double readScales = 0;
        if (scales < 0.04) {
            readScales = 0.06;
        } else if (scales > 0.96) {
            readScales = 0.96;
        } else {
            readScales = scales;
        }
        if (self.MhOsdeprogressViewSXAiXa) {
            _ZLmcEJshapeLayerWDClkp.strokeEnd = readScales;
        }
        
        if (!self.WfMpnlnoticeViewcVGfah) {
            self.WfMpnlnoticeViewcVGfah = [[UIImageView alloc] init];
            self.WfMpnlnoticeViewcVGfah.image = [UIImage imageNamed:@"icon_list_progress"];
            self.WfMpnlnoticeViewcVGfah.contentMode = UIViewContentModeScaleAspectFit;
            [self addSubview:self.WfMpnlnoticeViewcVGfah];
        }
        if (self.WfMpnlnoticeViewcVGfah) {
            self.WfMpnlnoticeViewcVGfah.width = 15;
            self.WfMpnlnoticeViewcVGfah.height = 15;
            self.WfMpnlnoticeViewcVGfah.centerY = 135;
            self.WfMpnlnoticeViewcVGfah.centerX = SCREEN_WIDTH*readScales;
        }
        
        if (!self.uBShqXnoticeLabelBqMXlb) {
            self.uBShqXnoticeLabelBqMXlb = [UILabel new];
            self.uBShqXnoticeLabelBqMXlb.textColor = RGB(207, 147, 111);
            self.uBShqXnoticeLabelBqMXlb.font = FONT(10);
            [self addSubview:self.uBShqXnoticeLabelBqMXlb];
        }
        
        if (self.uBShqXnoticeLabelBqMXlb) {
            self.uBShqXnoticeLabelBqMXlb.text = [NSString stringWithFormat:@"%.g%%", scales*100];
            [self.uBShqXnoticeLabelBqMXlb sizeToFit];
            self.uBShqXnoticeLabelBqMXlb.bottom = self.WfMpnlnoticeViewcVGfah.top - 5;
            self.uBShqXnoticeLabelBqMXlb.centerX = self.WfMpnlnoticeViewcVGfah.centerX;
        }
//
    }
    
    
}

- (void)prepareForReuse {
    _titleLabel.text = @"";
    _vGAUzptypeImgBvuKut.image = nil;
    _clQHSlriseImgiiCpNh.image = nil;
    _DqlqILaprLabelIPueGU.text = @"";
    
    
    [super prepareForReuse];
}

@end
